#ifndef __PROTECT_H
#define __PROTECT_H

#include <stdint.h>

/* PA protect */
#define PTT_PA_TEMP_WARN 70
#define PTT_PA_TEMP_FAULT 80
#define PTT_PA_CURRENT_WARN 12
#define PTT_PA_CURRENT_FAULT 15
#define PTT_PA_CURRENT_IMBALANCE 5
#define PTT_PA_RF_REFLECTION_WARN 10
#define PTT_PA_RF_REFLECTION_FAULT 20

/* SUB protect */
#define PTT_SUB_TEMP_WARN 65
#define PTT_SUB_TEMP_FAULT 75
#define PTT_SUB_CURRENT_WARN (PTT_PA_CURRENT_WARN * 3)
#define PTT_SUB_CURRENT_FAULT (PTT_PA_CURRENT_FAULT * 3)
#define PTT_SUB_CURRENT_IMBALANCE 5
#define PTT_SUB_RF_REFLECTION_WARN (PTT_PA_RF_REFLECTION_WARN * 3)
#define PTT_SUB_RF_REFLECTION_FAULT (PTT_PA_RF_REFLECTION_FAULT * 3)

/* WHOLE protect */
#define PTT_WHOLE_RF_REFLECTION_WARN 10
#define PTT_WHOLE_RF_REFLECTION_FAULT 20
#define PTT_WHOLE_RF_OVERLOAD_WARN 10
#define PTT_WHOLE_RF_OVERLOAD_FAULT 20

/* WARN time */
#define PTT_WARN_TIME_TEMP 60
#define PTT_WARN_TIME_CURRENT 10
#define PTT_WARN_TIME_RF_REFLECTION 10
#define PTT_WARN_TIME_RF_OVERLOAD 10

typedef enum
{
    kNormal,
    kAbnormal
} ptt_status_t;

typedef struct
{
    ptt_status_t pa_temp : 1;
    ptt_status_t pa_current : 1;
    ptt_status_t pa_rf_reflection : 1;
    ptt_status_t pa_rf_imbalance : 1;
    ptt_status_t sub_temp : 1;
    ptt_status_t sub_current : 1;
    ptt_status_t sub_rf_reflection : 1;
    ptt_status_t sub_rf_imbalance : 1;
    ptt_status_t whole_rf_reflection : 1;
    ptt_status_t whole_rf_overload : 1;
} ptt_status_bit_t;

extern ptt_status_bit_t protect;

// clang-format off
#define PTT_CRITICAL_STATE()        \
{                                   \
    .pa_temp = kAbnormal,           \
    .pa_rf_reflection = kAbnormal,  \
    .sub_temp = kAbnormal,          \
    .sub_rf_reflection = kAbnormal, \
    .whole_rf_reflection = kAbnormal,\
    .whole_rf_overload = kAbnormal, \
}
// clang-format on

uint32_t PTT_GetStatusBit();
ptt_status_t PTT_GetStatus();
void PTT_ClearStatus();
void PTT_Run();

#endif /* __PROTECT_H */